﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using MVCms.Core.Developers;
using MVCms.Core.Services;
using Plugin.Admin.UserAdministration.Models;

namespace Plugin.Admin.UserAdministration.Controllers
{
    public class UserAdministrationController :BaseController
    {
        [PluginModule(Name = "User List", Description = "User List", DisplayName = "User List")]
        [HttpGet]
        public PartialViewResult UserList()
        {
            UserListModel model = new UserListModel();
            model.Users = Membership.GetAllUsers().Cast<MembershipUser>().ToList();
            return PartialView("UserList", model);
        }

        [PluginModule(Name = "User Details", Description = "User Details", DisplayName = "User Details")]
        [HttpGet]
        public PartialViewResult UserDetails(Guid? providerUserKey)
        {
            MembershipUser user = providerUserKey == null
                                      ? Membership.GetUser(User.Identity.Name, false)
                                      : Membership.GetUser(providerUserKey, false);

            var model = new UserDetailsModel
                                         {
                                             User = user,
                                             UserRoles = Roles.GetRolesForUser(),
                                             Roles = Roles.GetAllRoles(),
                                             Pages = user.AllowedPages(),
                                             PageModules = user.AllowedPageModules()
                                         };
            return PartialView("UserDetails", model);
        }
    }
}